package com.lening.security.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lening.common.base.BaseController;
import com.lening.common.util.OssUtil;
import com.lening.common.web.Result;
import com.lening.community.controller.CommunityController;
import com.lening.community.vo.TableVo;
import com.lening.security.dto.PointsDTO;
import com.lening.security.po.PointsPO;
import com.lening.security.service.IPointsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author 赵子豪
 * @date 2024年06月04日 09时00分45秒
 * 巡更点位
 */
@Slf4j
@RestController
@RequestMapping("points")
public class PointsController extends BaseController<PointsPO, PointsDTO, IPointsService> {
    @Autowired
    private IPointsService iPointsService;

    @Autowired
    private CommunityController communityController;


    //分页
    @GetMapping("pointspage")
    public Page<PointsDTO> pointspage(PointsDTO pointsDTO) {
        Page<PointsDTO> page = iPointsService.pointspage(pointsDTO);
        return page;
    }

    //上传
//    @PostMapping("upload")
//    public Map<String, String> upload(@RequestParam("file") MultipartFile file) {
//        return iPointsService.upload(file);
//    }

    //    上传
    @PostMapping("UpLoad")
    public Result<?> upload(MultipartFile multipartFile) {
        String s = OssUtil.uploadFileAvatar(multipartFile);
        return Result.ok(s);
    }
    //记录
    @GetMapping("pointsrecordpage")
    public Page<PointsDTO> pointsrecordpage(PointsDTO pointsDTO) {
        Page<PointsDTO> pointsrecordpage = iPointsService.pointsrecordpage(pointsDTO);
        return pointsrecordpage;
    }

    //记录的修改，把空的改为有值
    @PutMapping("pointByid")
    public Result<?> pointByid(@RequestBody PointsDTO pointsDTO) {
        iPointsService.pointByid(pointsDTO);
        return Result.ok(true);
    }

    //四级联动
    @GetMapping("getAll")
    public List<TableVo> getAll() {
        return communityController.getAll();
    }

}